package model;

public class forTestAgain {

    public void changeTwo(byte[] bytes) {
        String str2 = "";
        byte temp;
        for (int i = 0; i < bytes.length; i++) {
            temp = bytes[i];
            bytes[i] = (byte) (~temp);
            str2 += Integer.toBinaryString((bytes[i] & 0xFF) + 0x100).substring(1);
        }
        System.out.println("取反后二进制:" + str2);
        // 取反后+1
        String add_1 = Solution(str2, "1");
        System.out.println("取反后二进制+1:" + add_1);
    }

    public static String Solution(String a, String b) {
        StringBuilder ans = new StringBuilder();
        int ca = 0;
        for (int i = a.length() - 1, j = b.length() - 1; i >= 0 || j >= 0; i--, j--) {
            int sum = ca;
            sum += i >= 0 ? a.charAt(i) - '0' : 0;
            sum += j >= 0 ? b.charAt(j) - '0' : 0;
            ans.append(sum % 2);
            ca = sum / 2;
        }
        ans.append(ca == 1 ? ca : "");
        return ans.reverse().toString();
    }
}
